home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Exchange
/
CD Exchange - Volume 1.iso
/
utils
/
misc
/
machv
/
programmer.lha
/
PrintMacros
/
PrintMacros.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-20
|
17KB
|
630 lines
#define PRTMAC_C
/* PrintMacros - Version 1.0 07-10-93 TAB STOPS SET TO 4!
Copywrite 1993 by Brian Moats
This program will print MachV macros to the printer, a file, or a window.
It requires MachV 5.0 or later to be running.
PrintMacros is called from SetMachV when you click on 'Print Macros'. The
configuration that is current at that time is the one whose macros will be
printed. It may also be called from the shell with one argument - the name
of the desired configuration. If no name is supplied, the current
configuration will be printed.
You may also create a macro that will execute this program. Example:
Exe_Cmd"PrintMacros \"GNU Emacs#?\""
This program may also serve as an example of how to interact with MachV.
It is not an elegant example of coding, however ;-).
If you have the appropriate catalog, PrintMacros will adapt to that
language. deutsch and français are provided.
Because MachV is locked by ObtainSemaphore() while printing, MachV can
not do anything. This may be inconvenient, but it is proper.
sc PrintMacros
slink lib:cback.o PrintMacros.o lib lib:sc.lib lib:debug.lib lib:amiga.lib
or to make smaller:
slink lib:cback.o PrintMacros.o sprintf.o lib lib:sc.lib lib:debug.lib \
lib:amiga.lib
(requires sprintf.a)
*/
#include <string.h>
#include <stdio.h>
#include <proto/asl.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/utility.h>
#include <clib/keymap_protos.h>
#include <clib/locale_protos.h>
#include <exec/execbase.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/ports.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/gadtools.h>
#define STRINGARRAY
#include "prtstr.h" /* created by catcomp */
#include "m43:headers/mach.h"
#include "m43:headers/machlib.h"
#include "m43:headers/machlib_protos.h"
#include "m43:headers/machlib_pragmas.h"
#define WIN_WIDTH 150
#define WIN_HEIGHT 76
#define WIN_FLAGS WFLG_ACTIVATE | WFLG_SMART_REFRESH | WFLG_CLOSEGADGET | \
WFLG_NOCAREREFRESH | WFLG_DEPTHGADGET | WFLG_DRAGBAR
#define IDCMP_FLAGS IDCMP_CLOSEWINDOW | IDCMP_GADGETUP | IDCMP_REFRESHWINDOW
#define WHERE_GID 100
#define GO_GID 101
#define ABORT_GID 102
#define PRINT_TO_CONSOLE 0
#define PRINT_TO_PRINTER 1
#define PRINT_TO_FILE 2
/* ============== Local Protos ============== */
static void handle_msg(void);
static BOOL main_window_open(void);
static void main_window_close(void);
static void set_language(void);
static void print_macros(void);
static void get_keytext(UWORD key,UWORD qual);
static BOOL XLateKeyQual(UWORD code,UWORD qual,UBYTE *buf);
static BOOL FileByRequest(void);
static void FreeFileRequestStruct(void);
static void writemacro(void);
static void writestr(char *s);
static void writehdr(void);
static void writedash(void);
static void writepadded(char *str,long max);
static void pause(void);
static void getquals(void);
/* ============= Globals ============== */
struct MachLibrary *MachBase;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *GadToolsBase, *LocaleBase, *KeymapBase, *AslBase;
APTR Catalog;
/* detach stuff */
long __stack = 4000;
long __priority = 0;
long __BackGroundIO = 1;
char *__procname = "PRINTMACROS";
extern BPTR _Backstdout; /* file handle we will write to with */
/* ============== Locals ============== */
static struct Window *mainw;
static struct TextAttr Topaz80 = {(STRPTR)"topaz.font",8,0,FPF_ROMFONT};
static struct VisualInfo *VI;
static char *where_labels[] = {NULL,NULL,NULL,NULL};
static struct Gadget *print_glist;
static WORD wle,conh,conw;
static WORD where_to;
static BOOL print_done,wb_to_back;
static LONG maxlines,maxconsolelines,linecnt;
static BPTR fh;
static char printdirname[80],printfilename[40];
static char blanks[43] = " ";
static char pressreturn[] = "Press Return";
static char curname[16]; /* name of macro currently being printed */
static char constr[50] = "Con:0/0/640/200/Macros/CLOSE";
static char qualtext[16],keytext[10];
static struct MacroObject *mo; /* macro currently being printed */
static struct MachCfg *cfg;
static ULONG toppix;
main(int argc, char **argv)
{
IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",37L);
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",37L);
GadToolsBase = OpenLibrary("gadtools.library",37L);
KeymapBase = (struct Library*)OpenLibrary("keymap.library",0L);
MachBase = (struct MachLibrary*)OpenLibrary("mach.library",37L);
if (cfg = MachBase->ml_CurConfig) { /* then MachV is running */
set_language();
where_to = PRINT_TO_CONSOLE;
if (argc > 1) {
argv++;
cfg = FindConfigByName(*argv);
}
if (cfg) {
if (main_window_open()) {
while (mainw) {
Wait(1L << mainw->UserPort->mp_SigBit);
handle_msg();
}
}
}
else
Write(_Backstdout,"Can't find configuration!\n",26L);
CloseLibrary((struct Library*)MachBase);
}
else
Write(_Backstdout,"MachV must be active first!\n",30L);
if (wb_to_back)
WBenchToBack();
if (IntuitionBase)
CloseLibrary((struct Library*)IntuitionBase);
if (GfxBase)
CloseLibrary((struct Library*)GfxBase);
if (GadToolsBase)
CloseLibrary(GadToolsBase);
if (KeymapBase)
CloseLibrary(KeymapBase);
}
static void print_macros(void)
{
UBYTE fullpath[160];
ULONG match_type;
switch (where_to) {
case PRINT_TO_CONSOLE:
sprintf(constr,"Con:0/0/640/%ld/Macros/CLOSE",conh);
fh = Open((STRPTR)constr,MODE_OLDFILE);
maxlines = maxconsolelines;
break;
case PRINT_TO_PRINTER:
fh = Open((STRPTR)"prt:",MODE_OLDFILE);
maxlines = 99999;
break;
case PRINT_TO_FILE:
if (AslBase = OpenLibrary((UBYTE*)"asl.library",37L)) {
if (FileByRequest()) {
strcpy((char*)fullpath,printdirname);
AddPart(fullpath,(UBYTE*)printfilename,160);
fh = Open((STRPTR)fullpath,MODE_NEWFILE);
FreeFileRequestStruct();
}
CloseLibrary(AslBase);
}
maxlines = 99999;
break;
}
print_done = 0;
linecnt = 0;
if (fh) {
writestr(cfg->mc_Title);
writehdr();
writedash();
ObtainSemaphore(&MachBase->ml_BaseSemaphore);
while (!print_done) {
match_type = MT_WILDCARDS; /* find all macros */
while (mo = FindByName(cfg,"#?",match_type)) {
match_type |= MT_MATCH_NEXT; /* keep going */
writemacro(); /* write to printer, file or window */
if (print_done) /* writestr() can set this */
break;
handle_msg(); /* check for abort gadget hit */
}
if (mo == NULL) /* did all, now pause */
pause();
break;
}
ReleaseSemaphore(&MachBase->ml_BaseSemaphore);
Close(fh);
fh = NULL;
}
}
static void handle_msg(void)
{
struct IntuiMessage *imsg;
struct Gadget *gadget;
ULONG iclass;
WORD icode;
while (mainw && (imsg = GT_GetIMsg(mainw->UserPort))) {
iclass = imsg->Class;
icode = imsg->Code;
gadget = (struct Gadget *) imsg->IAddress;
GT_ReplyIMsg(imsg);
if (iclass == IDCMP_GADGETUP) {
switch (gadget->GadgetID) {
case WHERE_GID:
where_to = icode;
break;
case GO_GID:
if (fh == NULL) /* not already printing? */
print_macros();
break;
case ABORT_GID:
print_done = 1;
break;
}
}
if (iclass == IDCMP_CLOSEWINDOW)
main_window_close();
}
}
static BOOL main_window_open(void)
{
struct Screen *public_screen;
struct Gadget *gad;
struct NewGadget ng;
int i,w,width;
where_labels[0] = AppStrings[MSG_DEST_WINDOW_GAD].as_Str;
where_labels[1] = AppStrings[MSG_DEST_PRINTER_GAD].as_Str;
where_labels[2] = AppStrings[MSG_DEST_FILE_GAD].as_Str;
width = 0; /* get max width for cycle gadget */
for (i=0;i<3;i++)
if ((w = strlen(where_labels[i])) > width)
width = w;
if ((public_screen = LockPubScreen(NULL)) != NULL) {
VI = GetVisualInfoA(public_screen,TAG_END);
toppix = public_screen->FirstWindow->BorderTop + 1;
wle = ((GfxBase->NormalDisplayColumns >> 1) - public_screen->LeftEdge - (WIN_WIDTH / 2));
conh = GfxBase->NormalDis